const {createServer} = require("http");
const {Server} = require("socket.io");

const httpServer = createServer();
const io = new Server(httpServer, {//跨域处理
    cors:{
        origin: "*",
        methods: ["GET","POST"]
    }
});

io.on("connection",(socket) =>{
    socket.on("sendMsg",(data) =>{
        // console.log(data);
        //给所有用户发送消息
        io.emit("pushMsg","你好，"+data);
    });
});
httpServer.listen(3000,function (){
    console.log("http://127.0.0.1:3000");
});